home *** CD-ROM | disk | FTP | other *** search
- Path: charnel.ecst.csuchico.edu!csusac!lesneskp
- From: lesneskp@ecs.ecs.csus.edu (Paul Lesneski)
- Newsgroups: comp.lang.c++
- Subject: help on USES relationships (& printer ostream)
- Date: 13 Apr 1996 05:12:53 GMT
- Organization: California State University, Sacramento
- Message-ID: <4knd4l$j7e@csusac.ecs.csus.edu>
- NNTP-Posting-Host: gaia.ecs.csus.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Greetings,
-
- I have a couple questions that I would greatly appreciate
- getting email back on (lesneskp@gaia.ecs.csus.edu). I
- deeply thank y'all for any help!
-
-
- A quickie first: I need to open an output stream to the
- printer, preferably as an ostream object (so I can use
- it identically to "cout"), but surprisingly cannot find
- any references on how to do so. I assume this is a
- simple task. Anyone??
-
- And...
-
- I'm having trouble implementing a "uses" relationship.
- A simple analogy would be that we have two unrelated
- classes, cl_a and cl_b, both which will be
- instantiated at the same scope, say main. I have
- designed some of cl_b's functionality based upon
- being able to use, or see, cl_a's public methods.
- I'm not sure how to structure header files or just
- plain reference cl_a's methods inside cl_b's methods.
-
- I could pass an instance of cl_a into cl_b's various
- methods that need visibility of cl_a, but this is rather
- tedious, as there are many of those. It feels much
- more logical to want cl_a's public methods to
- essentially seem global to cl_b.
-
- I could inherit cl_b from cl_a, but to me semi-frequent
- USE does not justify INHERITANCE, does it? That would
- also make quite a mess and destroy the concept of re-
- usability -- a complex network of "uses" relationships
- implemented as inheritance would create a web resembling
- a procedural design (sort of).
-
- I could instantiate (dynamically or not) cl_a inside
- any method in cl_b that needs to see cl_a, but then
- this turns from a "uses" relationship to a "has"
- relationship. Well, fine, except I'd like to know how
- to implement a "uses" relationship. Further, cl_a is
- something of a utility class, and it is used (thus
- would be instantiated) frequently enough that this would
- seem rather excessive and of poor design. Again, I feel
- as though having cl_a's public methods appear globally
- visible to cl_b is the best way to go.
-
- I could declare class cl_b to be a friend to class cl_a,
- but this is a cheap fix. There is no excuse for letting
- cl_b have access to all of cl_a when all it needs is
- access to cl_a's public methods.
-
- I'm unclear enough to have tried to just manipulate my
- header files, but have been unsuccessful thus far. Is
- this an angle that I can approach this problem with?
-
- Any tips are kindly appreciated.
-
-
- --
- ---
- |-) paul
-
- "The wise person knows that it is better to sit fishing on the banks
- of a remote mountain stream than to be emperor of the whole world."
-